package BasicDataType;

import java.net.InetAddress;
import java.util.List;
import java.util.List;
import java.util.StringTokenizer;

public class IPP {
	public InetAddress IPaddress;
	public int Port;

	public String getString() {
		if(IPaddress == null){
			return "0.0.0.0" +  "|" + Integer.toString(Port) + "|";
		}
		return IPaddress.getHostAddress() + "|" + Integer.toString(Port) + "|";
	}

	public IPP() {
	}

	public IPP(String str) {
		StringTokenizer st = new StringTokenizer(str, "|");
		try {
			String address = st.nextToken();
			if(address.equals("0.0.0.0"))
				IPaddress = null;
			else
				IPaddress = InetAddress.getByName(address);
			Port = Integer.parseInt(st.nextToken());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean inList(List<IPP> list) {
		for (IPP ipp : list) {
			if (IPaddress.equals(ipp.IPaddress) && Port == ipp.Port)
				return true;
		}
		return false;
	}
	

	
}
